package com.example.batch.config;

import com.example.batch.constant.JobConstant;
import com.example.batch.reader.MyMultiResourceFlatFileItemReader;
import com.example.batch.writer.MyMultiResourceFlatFileItemWriter;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2021/7/17 17:17
 */
@Configuration
public class BatchReadWriterConfig extends BaseConfig {

    final MyMultiResourceFlatFileItemReader reader;
    final MyMultiResourceFlatFileItemWriter writer;

    @Autowired
    public BatchReadWriterConfig(MyMultiResourceFlatFileItemReader reader,MyMultiResourceFlatFileItemWriter writer) {
        this.reader = reader;
        this.writer = writer;
    }

    @Bean
    public Step multiFileStep() {
        return stepBuilderFactory.get("multiFileStep")
                .<String, String>chunk(100)
                .reader(reader)
                .writer(writer)
                .build();
    }

    @Bean
    public Job multiFileDemo() {
        return jobBuilderFactory
                .get(JobConstant.MULTI_FILE_JOB_DEMO)
                .start(multiFileStep())
                .build();

    }

}
